package mulegame;

import javax.swing.JButton;
import java.awt.Color;
import javax.swing.border.LineBorder;
import javax.swing.ImageIcon;
import javax.swing.Action;

/**
 * sets tiles based on parameter and changes border color based on whether it's owned or not 
 * 
 * @author AREA 29
 *
 */
public class MapButton extends JButton{
	
    private Tile tile;
    private Color col = null;
    private int border = 0;
    private boolean flash = false;
    /**
     * 
     */
    public MapButton(){
        
    }
    
    /**
     * sets Action a
     * 
     * @param a action listener for button
     */
    public MapButton(Action a){
        super(a);   
    }
    
    /**
     *returns tile
     */
    public Tile getTile(){
        return tile;   
    }
    
    /**
     * sets tile object with colored border if it's owned and sets it with a new imagepath
     * 
     * @param t tile
     */
    public void setTile(Tile t){
        tile = t;
        border = 2;
        col = Color.BLACK;
        setBorderPainted(true);
        if(tile.isOwned()){
            border = 5;
            col = tile.getColor();
        }
        setBorder(new LineBorder(col, border));
	    setIcon(new ImageIcon(tile.getImagePath()));
    }
    
    /**
     * sets new border
     */
    public void flash(){
        int fBorder = flash ? border * 2 : border;
        setBorder(new LineBorder(col, fBorder));
        flash = !flash;
    }
    
    /**
     * resets Tile
     */
    public void reset(){
        setTile(tile);   
    }
}
